package design2;

/**
 * A calculator used to calculate the string representation of numbers.
 */
public class StringCalculator {
	
	private Cache<Number, String> numberToString = new Cache<>();
	
	/**
	 * Gets the string of the given number.
	 * 
	 * @param number
	 *    The number, for which to get the string.
	 * @return
	 *    The string of the given number.
	 */
	public String getString(Number number) {
		if (number == null) {
			throw new IllegalArgumentException("number should not be null.");
		}
		
		String string = numberToString.get(number);
		if (string == null) {
			string = number.toString();
			numberToString.put(number, string);
		}
		
		return string;
	}

}
